# encoding: utf-8
"""
尝试请求api,结果能获取到正确的数据
@Author:      "June"
@CreateTime:  2020/5/28 13:35 
@File:        request_test
@Project:     PyCharm
"""
import random
from urllib.parse import quote

import requests

from settings import userAgent

data = {
    "user_id": "75101545718",
    "max_cursor": "20",
    "count": "20",
    "retry_type": "no_retry",
    "iid": "1134339099473972",
    "device_id": "58937338600",
    "ac": "wifi",
    "channel": "xiaomi",
    "aid": "2329",
    "app_name": "douyin_lite",
    "version_code": "203",
    "version_name": "2.0.3",
    "device_platform": "android",
    "ssmix": "a",
    "device_type": "MX4 Pro",
    "device_brand": "Meizu",
    "language": "zh",
    "os_api": "21",
    "os_version": "5.0.1",
    "uuid": "867324020688152",
    "openudid": "534284e0db87a69b",
    "manifest_version_code": "203",
    "resolution": "1536*2560",
    "dpi": "640",
    "update_version_code": "2030",
    "_rticket": "1590588862601",
    "ts": "1590588861",
}

headers = {
    # 'User-Agent': "com.ss.android.ugc.aweme.lite/203 (Linux; U; Android 5.0.1; zh_CN; MX4 Pro; Build/LRX22C; Cronet/58.0.2991.0)",
    'User-Agent': "okhttp/3.10.0.1",
    'X-Gorgon': '03006cc040051c6f1d3e9c621ab0abc35940f5e2c14d8a08371e',
    'X-Khronos': '1590738935',
    # 'X-SS-REQ-TICKET': '1590737844985',
    # 'X-SS-TC': '0',
    # 'Cookie': 'odin_tt=eeae1b78cbd78e2deae975b6a68f25a0716198fa6d75ccb5f97f00470184f5e4c61325eaae78aae1ef8b0c56b86c4bb861dd9981be6a16bf82c1fe2d1176eac7; qh[360]=1; install_id=3562061066669069; ttreq=1$6232ae94ab293bf0f48863dc5417442a0e94bc5d'
}
# 关键字搜索URL，可获取user_id
keyword_url = 'https://api.amemv.com/aweme/v1/category/list/?cursor=0&count=5&retry_type=no_retry&iid=3562061066669069&device_id=69133478649&ac=wifi&channel=xiaomi&aid=2329&app_name=douyin_lite&version_code=203&version_name=2.0.3&device_platform=android&ssmix=a&device_type=MI+5s&device_brand=Xiaomi&language=zh&os_api=23&os_version=6.0.1&uuid=490000000185949&openudid=3cffa76ab4f67a77&manifest_version_code=203&resolution=810*1440&dpi=270&update_version_code=2030&_rticket=1590739838918&ts=1590739836&as=aa8b37fe485ed0c37e8b37&cp=fe988b37fe488b37fe9032&mas=01999323139959d3f37923b9b94534fc41d3f3792399d3f3f93319'
# 根据user_id获取指定用户的详情
url = 'https://aweme.snssdk.com/aweme/v1/aweme/post/?' \
      'user_id=101698659349&max_cursor=0&count=20' \
      '&retry_type=no_retry&iid=3562061066669069' \
      '&device_id=69133478649&ac=wifi&channel=xiaomi' \
      '&aid=2329&app_name=douyin_lite&version_code=203' \
      '&version_name=2.0.3&device_platform=android' \
      '&ssmix=a&device_type=MI+5s&device_brand=Xiaomi' \
      '&language=zh&os_api=23&os_version=6.0.1' \
      '&uuid=490000000185949&openudid=3cffa76ab4f67a77' \
      '&manifest_version_code=203&resolution=810*1440&dpi=270' \
      '&update_version_code=2030&_rticket=1590689576900' \
      '&ts=1590689575&as=aa9d3ffe485ecfff289d3f&cp=fe989d3ffe489d3ffe9032&mas=0199932313995959f319a3b9b945ccc02b59f319a32373595959f9'
result = requests.get(keyword_url, headers=headers)
print(result.json())
